package com.semac.client.componentes.botao;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class ButtonWidget extends Composite implements HasButtonClickHandlers, ClickHandler{

	private static ButtonUiBinder uiBinder = GWT.create(ButtonUiBinder.class);
	
	
	@UiField Label button;


	private HandlerManager eventBus;

	interface ButtonUiBinder extends UiBinder<Widget, ButtonWidget> {
		
	}

	
	public ButtonWidget() {
		this.eventBus = new HandlerManager(this);
		initWidget(uiBinder.createAndBindUi(this));
		this.button.addClickHandler(this);
	}
	
	/**
	 * accessible by outside components using uibinder
	 * @param buttonName
	 */
	public void setText(String buttonName){
		this.button.setText(buttonName);
		
	}
	

	@Override
	public void onClick(ClickEvent event) {
		this.eventBus.fireEvent(new ButtonClickEvent());
	}

	@Override
	public HandlerRegistration addButtonClickHandler(ButtonClickHandler handler) {
		return this.eventBus.addHandler( ButtonClickEvent.TYPE, handler);
	}
	
}
